/***************************************************
> Copyright (C) 2024 ==KINGYI== All rights reserved.
> File Name: rand_envirdata.c
> Author:MOKI
> Mail:1913964829@qq.com 
> Created Time: 2024年09月13日 星期五 18时52分22秒
***************************************************/
#include "global.h"
EnvironmentData randEnvirData()
{
    EnvironmentData data;
    data.temperature = randnum(0, 40);
    data.humidity = randnum(30, 70);
    data.light = randnum(0, 100) * 1000;
    data.air_quality = randnum(0, 150);
    data.timestamp = gettimestamp();
    return data;
}
int randnum(int min, int max)
{
    int outnum;
    srand((unsigned)time(NULL));
    outnum = rand() % (max - min) + min;
    return outnum;
}
int gettimestamp()
{
    struct timeval tv;
    gettimeofday(&tv, NULL);
    return tv.tv_sec;
}
